using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Fan.Dongping.DataAccess;
using Fan.Dongping.BusinessRules;
using System.Collections.Generic;

public partial class task_Task : PageBase
{
    string workflowId, documentId;

    protected void Page_Load(object sender, EventArgs e)
    {
        workflowId = Request.Params["W"];
        documentId = Request.Params["D"];
        // language = Request.Params["L"];

        if (IsPostBack == false)
        {
            DataTable dt = DocumentDA.GetDocumnet(workflowId, documentId);
            string c01 = string.Empty, c02 = string.Empty;
            string d01 = string.Empty;
            if (dt.Rows.Count > 0)
            {
                c01 = dt.Rows[0]["c01"] as string;
                c02 = dt.Rows[0]["c02"] as string;
                if ((dt.Rows[0]["d01"] is DBNull) == false)
                {
                    d01 = ((DateTime)dt.Rows[0]["d01"]).ToShortDateString();
                }
            }

            this.Title = string.Format(this.GetLocalResourceObject("DocTitleFormatString").ToString(), documentId, c02, d01);
            MasterPage_MasterPageA mp = (this.Master as MasterPage_MasterPageA);
            mp.SubTitle.Text = this.Title;
            if (string.IsNullOrEmpty(documentId) || string.IsNullOrEmpty(workflowId))
            {
                mp.PlaceHolderBody.Controls.Clear();
                Label labMsg = new Label();
                labMsg.CssClass = "msg";
                labMsg.Text = this.GetLocalResourceObject("DocNotExistString").ToString();
                mp.PlaceHolderBody.Controls.Add(labMsg);
            }
            else
            {
                string tmp = string.Format("W={0}&D={1}", workflowId, documentId);
                //UserSettingDA.UpdateFocusDoc(this.User.Identity.Name, tmp);
                HyperLinkDetail.NavigateUrl = string.Format("DocDetail.aspx?{0}", tmp);
                List<string> fs = DocumentBiz.GetAttachedFileSubName(workflowId, documentId);
                foreach (string f in fs)
                {
                    HyperLink hl = new HyperLink();
                    hl.Text = f;
                    hl.NavigateUrl = string.Format("../comm/Attach.aspx?F={0}", f);
                    PlaceHolder1.Controls.Add(hl);
                    PlaceHolder1.Controls.Add(new LiteralControl("<br>"));
                }

                //if (string.IsNullOrEmpty(language))
                //{
                //    language = "C";
                //}
                //else
                //{
                //    language = language.Trim().ToUpper();
                //}

                ImageMap1.ImageUrl = string.Format("CreateTaskGraph.aspx?W={0}&D={1}", workflowId, documentId);

                //
                DocumentData dd = DocumentData.CreateDocument(workflowId, documentId);
                //RectangleHotSpot[] rhs = dd.GetHotSpot();
                //foreach (RectangleHotSpot r in rhs)
                //{
                //    ImageMap1.HotSpots.Add(r);
                //}

                //
                selectedWorkflowDoc();
                selectedSubDoc();
                // bindItems();
            }
        }
    }
    protected void ImageMap1_Click(object sender, ImageMapEventArgs e)
    {
        string backString = e.PostBackValue;
        //backString = string.Format("showModelessDialog('{0}',window,'dialogWidth:320px;dialogHeight:310px;help:no;center:yes;status:no;scroll:no')", backString);

        backString = string.Format("window.open('{0}','','dialogWidth:320px;dialogHeight:310px;help:no;center:yes;status:no;scroll:no')", backString);
        //backString = string.Format("var i=0; if(var==1){{0}}",backString);
        //backString = string.Format("{0};setTimeout(\"var=1\",1000)",backString);
        backString = string.Format("<script language='javascript' type='text/javascript'>{0}</script>", backString);
        Response.Write(backString);
        //LabelDoc.Text = back;
    }

    private void selectedSubDoc()
    {
        //WebUtilities.SetSubDocColumns(workflowId, GridViewSubDoc);

        //DataTable dt = DocumentDA.GetSubDocumnets(workflowId, documentId);
        //GridViewSubDoc.DataSource = dt;
        //GridViewSubDoc.DataBind();
    }


    private void selectedWorkflowDoc()
    {

        //WebUtilities.SetDocColumns(workflowId, GridViewDocuments);

        //DataTable dt = DocumentDA.GetDocumnet(workflowId, documentId);
        //GridViewDocuments.DataSource = dt;
        //GridViewDocuments.DataBind();
    }

    //private void bindItems()
    //{
    //    DataTable items = ItemDA.GetItems(workflowId, documentId);

    //    GridViewItems.DataSource = items;
    //    GridViewItems.DataBind();
    //}
    protected void ButtonLanguage_Click(object sender, EventArgs e)
    {
        bool isEnglish = false;

        object o = Session["IsEnglish"];
        if (o != null)
        {
            isEnglish = (bool)o;
        }

        Session["IsEnglish"] = !isEnglish;

        Response.Redirect(Request.RawUrl);
    }
}
